package com.tibco.notepad.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tibco.notepad.domain.Notepad;
import com.tibco.notepad.util.Constant;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

@SuppressLint("CommitPrefEdits")
public class PreferencesUtil {
	public static SharedPreferences mSharedPreferences;
	public static Editor mEditor;
	private Context context;
	@SuppressWarnings("unused")
	public PreferencesUtil(Context context) {
		if (null == mSharedPreferences) {
			mSharedPreferences = context.getSharedPreferences("notepad",
					Context.MODE_APPEND);
		}
		if (null == mEditor) {
			mEditor = mSharedPreferences.edit();
		}
	}

	public void save(String title, String content) {
		mEditor.putString(Constant.NOTE_TITLE, title);
		mEditor.putString(Constant.NOTE_CONTENT, content);
		mEditor.commit();
	}

	public Map<String, String> getPreferences(){
		Map<String, String> params = new HashMap<String, String>();
		params.put(Constant.NOTE_TITLE, mSharedPreferences.getString(Constant.NOTE_TITLE, ""));
		params.put(Constant.NOTE_CONTENT,mSharedPreferences.getString(Constant.NOTE_CONTENT, ""));
		return params;
	}
	
	public String getTitle() {
		return mSharedPreferences.getString(Constant.NOTE_TITLE, "");
	}

	public String getContent() {
		return mSharedPreferences.getString(Constant.NOTE_CONTENT, "");
	}
	
	@SuppressLint("SimpleDateFormat")
	public static String getTime() {
		SimpleDateFormat formatter = new SimpleDateFormat("yy-MM-dd  HH:mm:ss");
		String str = formatter.format(new Date());
		return str;
	}

}
